home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PGP5GUI - A GUI using Magic User Interface v3.8
- **
- ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
- **
- ** This source code is released as FREEWARE - Use it for whatever you like,
- ** as long as NO financial reward is gained by you for such usage.
- **
- ** If you use any parts of the this source code for anything, give ME credit
- ** wherever credit is due, please ;-)
- */
-
- /*
- ** Functions to handle the interface between PGPK and the GUI
- */
-
- /* Library stuff */
- #include <libraries/mui.h>
- #include <dos/dostags.h>
-
- /* Prototypes */
- #ifdef __GNUC__
- #include <clib/muimaster_protos.h>
- #include <proto/alib.h>
- #endif
-
- #include <proto/muimaster.h>
- #include <proto/exec.h>
- #include <clib/alib_protos.h>
- #include <clib/alib_stdio_protos.h>
- #include <proto/dos.h>
-
- /* Ansi */
- #include <string.h>
-
- /* Include generated by GenCodeC */
- #include "PGP5GUI.h"
-
- BOOL listget = FALSE;
-
- char *caution_str = "CAUTION!";
- char *permanent_str = "The result of this function is PERMANENT...\nAre you sure you want to continue?";
- char *yesno_str = "Yes|No";
-
- extern char *tempfile;
- extern char *pgp5_tmp_asc;
-
- extern char *keys_extractpath;
- extern char *keys_extractfile;
-
- extern char *exec_buff;
- extern char *keyidsbuff;
-
- extern char *OK_str;
- extern char *ReadyMSG;
-
- extern char *keyselection[];
- extern ULONG frtags[];
-
- extern int GenerateKeyStrings(char *filename);
- extern int SelectPGPKey(struct ObjApp *app, char *sel[], char *title, ULONG multiselect);
- extern BOOL GetSaveASLFileName(struct ObjApp *app, char *hail, char *pathbuff, char *filebuff, char *tofile);
-
- extern void PGP5_Execute(UBYTE *command, struct ObjApp *app);
- extern LONG GetCycle(Object *obj);
-
- extern BOOL ReadClipToFile(char *tmp, struct ObjApp *app);
-
- void
- PGPK_list(struct ObjApp *App)
- {
- listget = TRUE;
-
- /* Get public-key list using "PGPK -l >T:pgp5keys" */
- sprintf(exec_buff, "PGPK -l >%s", tempfile);
- PGP5_Execute(exec_buff, App);
-
- listget = FALSE;
-
- /* Get key info strings into keystable[] */
- if (GenerateKeyStrings(tempfile))
- {
- /* Probably failed if PGP5_Execute failed */
- MUI_Request(App->App, App->WI_Main, 0, "FATAL ERROR...", OK_str,
- "Couldn't access '%s'", tempfile);
- }
-
- /* Wake up the parent window */
- set(App->WI_Main,MUIA_Window_Sleep,FALSE);
-
- /* Activate the parent window */
- set(App->WI_Main,MUIA_Window_Activate,TRUE);
-
- set(App->TX_Status, MUIA_Text_Contents, ReadyMSG);
- }
-
-
- /*
- ** -a [keyfile keyfiles...]
- ** Adds the contents of 'keyfile(s)' to your keyring.
- */
- void
- Do_ADD_KEYADD(struct ObjApp *App)
- {
- char *addkeybuff = "\0";
- LONG clipmode;
-
- clipmode = GetCycle(App->CY_KeysAdd_CLIP);
-
- if (clipmode)
- {
- if (ReadClipToFile(pgp5_tmp_asc, App))
- {
- addkeybuff = pgp5_tmp_asc;
- }
- }
- else
- {
- get(App->STR_PA_Keys_ADD_KEYFILE,MUIA_String_Contents,&addkeybuff);
- }
-
- if (*addkeybuff)
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -a \"%s\"", addkeybuff);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- if (clipmode)
- {
- /* Clipboard mode... Delete the temporary file (T:pgp5.tmp.asc) */
- DeleteFile(pgp5_tmp_asc);
- }
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
-
-
- /*
- ** -c [userid]
- ** Checks the signatures of all keys on your public keyring.
- ** If [userid] is specified, only the signatures on that key
- ** are checked.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYCHECK(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Check Key(s)...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /* Build up the command line to send to DOS */
- strcpy(exec_buff, "PGPK -c ");
-
- /* Check for a selected userID. */
- if (*keyselection[0])
- strcat(exec_buff, keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -d <userid>
- ** Toggles the disablement of <userid>'s key on your public keyring.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYDISABLE(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "(En/Dis)able A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -d %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -e <userid>
- ** Edits <userid>'s key. If this is your key, it allows you to
- ** edit your userid(s) and passphrase. If it is someone else's
- ** key, it allows you to edit the trust you have in that person
- ** as an introducer.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYEDIT(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Edit A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -e %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -r <userid>
- ** Removes <userid>'s key from your public and private keyring (if it's there)
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYREMOVE(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Remove A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -r %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -rs <userid>
- ** Removes the given signature from your public keyring.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYREMSIG(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Remove A Signature...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -rs %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -ru <userid>
- ** Removes the given userid from your public and private keyrings.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYREMUID(struct ObjApp *App)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Remove A UserID...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -ru %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** --revoke <userid>
- ** PERMANENTLY revokes the user selected key.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYREVOKE(struct ObjApp *App)
- {
- int err;
-
- /* Warn about irreversible function! */
- if (MUI_Request(App->App, App->WI_Main, 0, caution_str, yesno_str, permanent_str))
- {
- err = SelectPGPKey(App, keyselection, "Permanently Revoke A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK --revoke %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- /* If user didn't click Cancel... */
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened! */
- }
- }
-
- return(TRUE);
- }
-
-
- /*
- ** --revokes <userid>
- ** Permanently revokes a signature (if any) on the user selected key.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYREVOKESIG(struct ObjApp *App)
- {
- int err;
-
- /* Warn about irreversible function! */
- if (MUI_Request(App->App, App->WI_Main, 0, caution_str, yesno_str, permanent_str))
- {
- err = SelectPGPKey(App, keyselection,
- "Permanently Revoke Your Signature On A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK --revokes %s", keyselection[0]);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- else
- {
- /* If user didn't click Cancel... */
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened! */
- }
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -s <userid> [-u <yourid>]
- ** Signs <userid>'s key with your default signing key.
- ** If -u is specified, uses that key, instead.
- ** Note that PGPK only allows for 1 selected userID!
- */
- BOOL
- Do_EDIT_KEYSIGN(struct ObjApp *App, BOOL doID)
- {
- int err;
-
- err = SelectPGPKey(App, keyselection, "Sign A Key...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -s %s", keyselection[0]);
-
- if (doID)
- {
- err = SelectPGPKey(App, keyselection, "Signing Key To Use...",
- MUIV_Listview_MultiSelect_None);
-
- if (!err)
- {
- strcat(exec_buff, " -u ");
- strcat(exec_buff, keyselection[0]);
- }
- }
-
- /* If no error from doID's check... */
- if (!err)
- {
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -g
- ** Generate a public/private key pair.
- */
- void
- Do_MISC_KEYGEN(struct ObjApp *App)
- {
- /* Build up the command line to send to DOS */
- strcpy(exec_buff, "PGPK -g");
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Reload (edited) new list */
- PGPK_list(App);
- }
-
-
- /*
- ** -x <userids> +force -o <outfile>
- ** Extracts the specified userids keys in ASCII-armored form.
- */
- BOOL
- Do_MISC_KEYEXTRACT(struct ObjApp *App)
- {
- int err, i;
-
- /* Title for the file requester */
- char title[] = "Save Public Key(s) As...";
- char tofile[512];
-
- err = SelectPGPKey(App, keyselection, "Extract Key(s)...",
- MUIV_Listview_MultiSelect_Default);
-
- if (!err)
- {
- /*
- ** Check for a selected userID.
- ** If nothing was selected, then skip this.
- */
- if (*keyselection[0])
- {
- strcpy(keyidsbuff, keyselection[0]);
-
- for (i = 1; i < 256; i++)
- {
- if (*keyselection[i])
- {
- strcat(keyidsbuff, " ");
- strcat(keyidsbuff, keyselection[i]);
- }
- else
- break;
- }
-
- /* Get name of file to save key to... */
- if (GetSaveASLFileName(App, title, keys_extractpath, keys_extractfile, tofile))
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -x %s +force -o \"%s\"", keyidsbuff, tofile);
-
- /* Send the command to DOS and the output to 'tofile' */
- PGP5_Execute(exec_buff, App);
- }
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-
-
- /*
- ** -l[l] [userids]
- ** Lists information about a key. '-ll' lists more information
- ** about a key. If [userids] are specified, then those keys are listed.
- ** Otherwise, all keys are listed.
- */
- BOOL
- Do_MISC_KEYLIST(struct ObjApp *App)
- {
- int err, i;
-
- err = SelectPGPKey(App, keyselection, "List Key(s)...",
- MUIV_Listview_MultiSelect_Default);
-
- if (!err)
- {
- /* If we have a selected userID we output verbose info about the key(s) */
- if (*keyselection[0])
- {
- strcpy(keyidsbuff, keyselection[0]);
-
- for (i = 1; i < 256; i++)
- {
- if (*keyselection[i])
- {
- strcat(keyidsbuff, " ");
- strcat(keyidsbuff, keyselection[i]);
- }
- else
- break;
- }
-
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPK -ll %s", keyidsbuff);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
-
- return(TRUE);
- }
-